export default {
    data() {
        return {
            center: this.mapInfo.center,
            zoom: this.mapInfo.zoom,
            enable: this.mapInfo.enable,
            style: this.mapInfo.style,
            adcode: this.mapInfo.adcode,
            map_content: null,
            data_content: [],
            map: undefined,
            viewMode: this.mapInfo.viewMode
        };
    },
    mounted() {
        this.initMap();
        this.getMapSetting();
    },
    beforeDestroy() {
        this.map.destroy()
    },
    computed: {
        map_info: function () {
            return {
                center: this.center, //地图中心
                zoom: this.zoom, //地图级别
                mapStyle: this.style,
                rotateEnable: true,
                dragEnable: this.enable,
                scrollWheel: this.enable,
                doubleClickZoom: this.enable,
                bubble: true,
                // viewMode: "2D",
                viewMode: this.viewMode,
            };
        },
    },
    props: {
        mapInfo: {
            type: Object,
            default: function () {
                return {
                    center: [116.493846, 40.263609],
                    zoom: 8,
                    enable: true,
                    style: "amap://styles/73767376d1e21c535f3e909bdd72a3fa",
                    adcode: 110000,
                    viewMode:"2D"
                };
            },
        },
    },
    methods: {
        initMap: function () {
            this.map = new AMap.Map(this.$el, this.map_info);
        },
        getMapSetting: function () {
            let that = this
            this.map.on("zoomchange", () => {
                console.log(that.map.getZoom());
            });
            this.map.on("moveend", () => {
                let center = that.map.getCenter()
                console.log(`${center.lng},${center.lat}`);
            })
        }
    },
}